package com.imooc.service;

import com.imooc.GirlException.GirlException;
import com.imooc.ResultEnum.ResultBoyEnum;
import com.imooc.domain.Girl;
import com.imooc.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Created by chenxin on 2017/4/25.
 */
@Service
public class GirlService {
    @Autowired
    private GirlRepository girlRepository;
    @Transactional
    public void InsertTwo(){
        Girl girl1=new Girl();
        girl1.setCupSize("C");
        girl1.setAge(16);

        Girl girl2=new Girl();
        girl2.setCupSize("K");
        girl2.setAge(39);

        girlRepository.save(girl1);
        girlRepository.save(girl2);
    }

    public void getAgeById(Integer id) throws Exception {

      Girl girl=  girlRepository.findOne(id);
      Integer age=girl.getAge();
      if(age<10){
          //年龄太小，不能谈恋爱
        // throw new GirlException(100,"年龄太小，不能谈恋爱");
          throw new GirlException(ResultBoyEnum.GRRL_ERRORLOVE);
      }
      else if(age>16 && age<28){
          //这个时候真好可以谈恋爱
          throw new GirlException(ResultBoyEnum.GRRL_ERRORLOVE);
      }
    }
    //
    public Girl findOne(Integer id){
        return girlRepository.findOne(id);
    }
}
